<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>我的地址</title>
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/page.css">
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/media.js"></script>
    <script src="../js/common.js"></script>
    <style>
        .add_price {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            justify-content: space-between;
            align-items: center;
            height: .4rem;
            background: #fff;
        }

        .add_price .left {
            font-size: .14rem;
            padding-left: .12rem;
        }

        .add_price .left font {
            color: red;
        }

        .add_price .right {
            display: inline-block;
            width: 1.27rem;
            height: .4rem;
            line-height: .4rem;
            background: rgba(95, 49, 4, 1);
            color: #fff;
            font-size: .14rem;
            text-align: center;
        }
    </style>
</head>

<body>
    <!--头部-->
    <div class="public-header flex">
        <!--<span class="public-header-left-search"></span>-->
        <span class="public-header-left-back"></span>
        <span class="public-header-center">我的地址</span>
        <span class="public-header-right">完成</span>
    </div>

    <!--正文-->
    <div class="my-address bc-gray">
        <ul>
            <li class="flex" v-for="item in datas">
                <span :class="{active:item.selec}" :data-add='item.addId' @click='save_address(this)'></span>
                <div>
                    <p class="p1">{{item.name}}</p>
                    <p class="p2">{{item.addDesc}}</p>
                </div>
                <em></em>
            </li>

        </ul>
        <p class="tip flex">
            <span class=""></span>

            <i class="p2" onclick='javascript:window.location.href="../page/Add-address.html"'>添加地址</i>

            <em></em>
        </p>
        <p class="flex add_price">
            <span class="left">合计:￥<font id="price">1000</font></span>
            <span class="right" @click='pay()'>
                提交订单
            </span>
        </p>
    </div>

    <script src='../js/vue.js'></script>
    <script src='../js/vue-resource.min.js'></script>

    <script>
        $(function () {
            var addid;

            if (getQueryString('order_id') != null) {
                $('.add_price').hide();
                $('.public-header .public-header-right').click(function () {
                    $.ajax({
                        url: base_url + 'ZITAOHUI/order/setAddr',
                        data: {
                            addid: 1,
                            orderid: getQueryString('order_id')
                        },
                        success: function (data) {
                            console.log(data)
                            if (data.code == 1) {
                                alert('定制成功');
                                window.location.href = '../index.html'

                            }
                        }
                    })
                })
            } else {
                $('.public-header').hide();
            }

            new Vue({
                el: 'body',
                data: {
                    addid:''
                },
                ready: function () {
                    this.$http.get(base_url + 'ZITAOHUI/address/list', {
                        params: {
                            uid: u_id,
                        }
                    }).then(function (data) {
                        console.log(data)
                        let all_data = data.data.extend.data;
                        for (let i = 0; i < all_data.length; i++) {
                            all_data[i].selec = 0
                        }
                        this.$set('datas', all_data)
                    })
                },
                methods: {
                    pay: function () {
                        this.$http.get(base_url + 'ZITAOHUI/user/pay', {
                            params: {
                                uid: u_id,
                                produceid: 1,
                                price: $('#price').html(),
                                addid: this.addid
                            }
                        }).then(
                            function (data) {
                                console.log(data)
                                if (data.data.code = 1) {
                                    alert('购买成功');
                                    window.location.href = '../page/Buyer-order.html'
                                }
                            },
                            function () {

                            }
                        )
                    },
                    save_address: function (t) {
                        console.log(t);
                        if (t.item.selec == 0) {
                            for (let i = 0; i < t.datas.length; i++) {
                                t.datas[i].selec =0
                            }
                            t.item.selec = 1;
                            this.$set('addid',t.item.addId)
                        } else {
                            t.item.selec = 0;
                        }

                    }
                }

            })
        })
    </script>

</body>

</html>